﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AgileLogistics
{
    /// <summary>
    /// Login.xaml 的交互逻辑
    /// </summary>
    public partial class Login : Window
    {
        ViewModel.MainViewModel vm;
        Model.DBContext dBContext = new Model.DBContext();
        public Login()
        {
            InitializeComponent();
            vm = DataContext as ViewModel.MainViewModel;
        }

        private void btn_Login_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txt_UserId.Text))
            {
                txt_UserId.Focus();
                txt_info.Text = "请输入用户账号";
               
                return;
            }
            if (string.IsNullOrEmpty(txt_Password.Password))
            {
                txt_Password.Focus();
                txt_info.Text = "请输入用户密码";
                
                return;
            }

           var user = dBContext.DB.Queryable<Model.Users>().Where(u => u.Id == txt_UserId.Text && u.Password == txt_Password.Password).First();
                
            if(user ==null)
            {
                txt_info.Text = "账号或密码错误！";
                return;
            }else
            {
                Comm.Temp.LoginUser = user;
                AgileLogistics.UI.MainWindow win = new UI.MainWindow();
                win.Show();

               
                this.Close();
            }
        }
    }
}
